package edu.uwm.universitydb.dao.professor;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import edu.uwm.universitydb.framework.nontransactional.db.command.impl.NonTransactionalDataManipulationCommandBase;
import edu.uwm.universitydb.model.Professor;

/**
 * <code>UpdateStudentCommand</type>
 * command class to update  student table
 * 
 */
public class UpdateProfessorCommand extends NonTransactionalDataManipulationCommandBase
{
    /** static string holding the update sql */
    private static final String SQL =
        "update university.professor set name=?, age=?, rank=?, research_speciality=? " +
        "where prof_ssn=?";

    /** attribute holding the student to be updated */
    private final Professor mProfessor;

    /**
     * 
     * @param student
     */
    public UpdateProfessorCommand(final Professor student)
    {
        mProfessor = student;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#getSQL()
     */
    @Override
    public String getSQL()
    {
        return SQL;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#setParameters(java.sql.PreparedStatement)
     */
    @Override
    public void setParameters(final PreparedStatement pStmt) throws SQLException
    {
        // set name
        final String name = mProfessor.getName();
        pStmt.setString(1, name);

        // set age
        final Integer age = mProfessor.getAge();
        pStmt.setInt(2, age);

        // set rank
        final String program = mProfessor.getRank();
        pStmt.setString(3, program);

        // set speciality
        final String speciality = mProfessor.getResearchSpeciality();
        pStmt.setString(4, speciality);

        
        // set ssn
        final String ssn = mProfessor.getSsnNum();
        pStmt.setString(5, ssn);

    }

}
